<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>航空主单列表</title>
        <% include("/common/common_css_js.html"){} %>
        <script type="text/javascript" src="${base!}/js/LodopFuncs.js?d=${jdate!}"></script>
    </head>
    <body>

        <object style="display: none" id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
            <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
        </object>

        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
                <span>主单号：</span><input id="keyMasterBillCode" name="keyMasterBillCode" emptyText="请输入主单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="主单号不能为空" />
                <span class="separator"></span>
                <span>配货方式:</span><input id="keyloadWayId" name="keyloadWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择配货方式" />
                <span class="separator"></span>
                <span>承运方式:</span><input id="keyTransportWayId" name="keyTransportWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择承运方式"/>
                <span class="separator"></span>
                <span>对账状态:</span>
                <input id="keyAccountCheckStatusId" name="keyAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择对账状态"/>

                <span class="separator"></span>
                <span>收货人:</span>
                <input id="keyReceiveCustomerName" name="keyReceiveCustomerName" style="width:250px;"  emptyText="收货人名称"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="收货人名称不能为空"/>


                <div style="margin-top: 5px"></div>
                <span>开单日期：</span>
                <input id="keyOpenMasterBillStartDate" name="keyOpenBillStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>--<input id="keyOpenMasterBillEndDate" name="keyOpenBillEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>
                <span class="separator"></span>
                <span>目的市:</span>
                <input id="keyDestCityId" name="keyDestCityId" class="mini-treeselect"
                       virtualScroll="true"   expandOnLoad="2"
                       multiSelect="false" valueField="id" textField="name" parentField="pid" allowInput="true" valueFromSelect="true"
                       style="width: 220px;" expandOnLoad="true" requiredErrorText="没有选择目的市" nullItemText="请选择..." />
                <span class="separator"></span>
                <span>始发机场:</span>
                <div id="keyAirportId" name="keyAirportId" class="mini-combobox" style="width:150px;"  popupWidth="1000" textField="name" valueField="id"
                     requiredErrorText="始发机场不能为空"
                     allowInput="true"
                     emptyText="始发机场名称">
                    <div property="columns">
                        <div header="ID" field="id" width="30"></div>
                        <div header="机场名称" field="name"></div>
                        <div header="简称" field="shortName"></div>
                    </div>
                </div>
                <span class="separator"></span>
                <span>外发单位:</span>
                <div id="keyOutUnitId" name="keyOutUnitId"
                     class="mini-combobox"
                     style="width:250px;"
                     popupWidth="600" textField="name" valueField="id"
                     allowInput="true" requiredErrorText="外发单位不能为空"
                     emptyText="外发单位名称">
                    <div property="columns">
                        <div header="ID" field="id" width="30"></div>
                        <div header="单位名称" field="name"></div>
                        <div header="联系人" field="contact"></div>
                        <div header="电话" field="phone"></div>
                        <div header="地址" field="address"></div>
                    </div>
                </div>

                <div style="margin-top: 5px"></div>
                <% if(so.hasPermission("bMasterBillFlight:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="searchMasterBill()">查询</a>
                <% } %>

                <% if(so.hasPermission("bMasterBillFlight:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>

                <span class="separator"></span>

                <% if(so.hasPermission("bMasterBillFlight:edit")){%>
                    <a class="mini-button" iconCls="icon-edit" onclick="editMasterBillShow()">编辑</a>
                <% } %>

                <% if(so.hasPermission("bMasterBillFlight:invalid")){%>
                    <a class="mini-button" iconCls="icon-cancel" onclick="cancelMasterBill()">作废</a>
                <% } %>

                <% if(so.hasPermission("bMasterBillFlight:delete")){%>

                    <a class="mini-button" iconCls="icon-remove" onclick="deleteMasterBill()">删除</a>

                <% } %>

                <% if(so.hasPermission("bMasterBillFlight:noCheckPullDelete")){%>

                    <a class="mini-button" iconCls="icon-remove" onclick="noPullStatusCheckDeleteMasterBill()">不检测拉货状态删除</a>

                <% } %>

                <span class="separator"></span>
                <% if(so.hasPermission("bMasterBillFlight:pull")){%>
                    <a class="mini-button" iconCls="icon-edit" style="width: 100px" onclick="dropMasterBillShow()">拉货</a>
                <% } %>

                <span class="separator"></span>
                <% if(so.hasPermission("bMasterBillFlight:print")){%>
                    <a class="mini-button" iconCls="icon-edit" onclick="showPrintMasterBill()">主单打印</a>
                <% } %>

                <span class="separator"></span>

                <% if(so.hasPermission("bMasterBillFlight:download")){%>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="航空主单信息表"/>
                <% } %>

                <div style="margin-top: 5px"></div>
                <span style="color: red;font-weight: bold">
                    <span>注:1.【初始配载分单号】表示主单初始配载时所包含的分单号 </span>
                    <span style="margin-left: 10px">2.主单如果做过全拉货操作，则主单下配载分单会被清空，而列表中显示的【初始配载分单号】不会清除(用于标识地面运费成本标识) </span>
                </span>
            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/master_bill_manage/flight/queryFlightMasterBill" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 multiSelect = "true" allowResize="true"
                 showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                 allowSortColumn = "true"
                 sortField="createTime"
                 sortOrder="desc"
                 onshowrowdetail="onShowRowDetail"
                 ondrawsummarycell="summaryRight"
            >
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div type="expandcolumn" ></div>
                    <div field="id" width="140" headerAlign="center" align="center" allowSort="true"  renderer="showMasterBillRender">航空主单号</div>
                    <div field="loadNativeBillIds" width="140" headerAlign="center" align="center">初始配载分单号</div>
                    <div field="loadWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">配货方式</div>
                    <div field="transportWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">承运方式</div>
                    <div field="outUnitId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"outUnit"}' renderer="commonRender">外发单位</div>
                    <div field="destCityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">目的市</div>


                    <div field="goodsTypeId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">货物类型</div>
                    <div field="airportId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airport"}' renderer="commonRender">始发机场</div>
                    <div field="airlinesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airlines"}' renderer="commonRender">航空公司</div>
                    <div field="flightDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd" renderer="ondayRenderer">航班日期</div>
<!--                    <div field="flightNo" width="140" headerAlign="center" align="center" allowSort="true">航班ID</div>-->
                    <div field="flightName" width="140" headerAlign="center" align="center" allowSort="true">航班名</div>

<!--                    <div field="agentCompanyId" width="140" headerAlign="center" align="center" allowSort="true">代理公司ID</div>-->
                    <div field="agentCompanyName" width="140" headerAlign="center" align="center" allowSort="true">代理公司名</div>
                    <div field="agentCompanyPhone" width="140" headerAlign="center" align="center" allowSort="true">代理公司电话</div>
                    <div field="agentCompanyAddress" width="140" headerAlign="center" align="center" allowSort="true">代理公司地址</div>

                    <div field="receiveCustomerName" width="140" headerAlign="center" align="center" allowSort="true">收货人名称</div>
                    <div field="receiveCustomerPhone" width="140" headerAlign="center" align="center" allowSort="true">收货人电话</div>
                    <div field="receiveCustomerAddress" width="140" headerAlign="center" align="center" allowSort="true">收货人地址</div>

                    <div field="freightSpeciesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">运价种类</div>
                    <div field="goodsCodeId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">商品代号</div>
                    <div field="goodsName" width="140" headerAlign="center" align="center" allowSort="true" >货物名称</div>
                    <div field="packingWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">包装方式</div>
                    <div field="airportGoodsSiteId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airportGoodsSite"}' renderer="commonRender">航空货站</div>

                    <div field="totalNumber" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">总件数</div>
                    <div field="actualWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">实际重量</div>
                    <div field="chargeableWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">计费重量</div>
                    <div field="weightRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" >重量费率</div>
                    <div field="transportCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">航空运费</div>
                    <div field="pullDisposeTransportCostAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">航空运费调整金额</div>
                    <div field="declaredValue" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">声明价值</div>
                    <div field="groundAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">地面运费</div>
                    <div field="pullDisposeGroundAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">地面运费调整金额</div>
                    <div field="stampDuty" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">印花税</div>
                    <div field="insuranceFee" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">保险费</div>
                    <div field="airlinesAddCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">航空附加费</div>
                    <div field="pullDisposeAirlinesAddCostAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">航空附加费调整金额</div>
                    <div field="otherCharges" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">其他费用</div>
                    <div field="pullDisposeOtherChargesAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">其他费用调整金额</div>
                    <div field="otherChargesComment" width="140" headerAlign="center" align="center" allowSort="true">其他费用说明</div>

                    <div field="masterBillPaymentMethodId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">付款方式</div>
                    <div field="totalAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">总金额</div>
                    <div field="dropAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">调整金额</div>
                    <div field="settlementAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_redBoldMoneyRenderer" summaryType="sum">
                        <span style="color: red;font-weight: bold">结算金额</span>
                    </div>

                    <div field="openMasterBillDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">开单日期</div>
                    <div field="openMasterBillDepartmentId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"department"}' renderer="commonRender">开单部门</div>
                    <div field="openMasterBillUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">开单人</div>
                    <div field="comment" width="140" headerAlign="center" align="center" allowSort="false">备注</div>
                    <div field="transportCostStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">航空运费状态</div>
                    <div field="groundAmountStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">地面运费状态</div>
                    <div field="airlinesAddCostStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">航空附加费状态</div>
                    <div field="dropStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">拉货状态</div>
                    <div field="accountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">对账状态</div>
                    <div field="settlementStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">结算状态</div>


                    <div field="transportCostAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">航空运费对账状态</div>
                    <div field="groundAmountAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">地面运费对账状态</div>
                    <div field="airlinesAddCostAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">燃油附加费对账状态</div>
                    <div field="otherChargesAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">其他费用对账状态</div>


                    <div field="createTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">创建时间</div>
                    <div field="createUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">创建用户</div>
                    <div field="updateTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">更新时间</div>
                    <div field="updateUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">更新用户</div>

                </div>
            </div>

        </div>

        <!-- 子表 -->
        <div id="detailDiv" style="display:none; margin-left: 50px">
            <div id="detailGrid" class="mini-datagrid" style="width:1400px;height:200px;"
                 pageSize="5" sizeList="[5,10,15,20]"
                 url="${base}/pages/master_bill_manage/flight/queryNativeBillList">
                <div property="columns">
                    <div field="nativeBillId" width="50" headerAlign="center" align="center"  renderer="showNativeBillRender" >分单号</div>
                    <div field="loadNumber" width="70" headerAlign="center" align="right" >配载总件数</div>
                    <div field="loadActualWeight" width="70" headerAlign="center" align="right" >配载实际重量</div>
                    <div field="loadChargeableWeight" width="70" headerAlign="center" align="right" >配载计费重量</div>
                    <div field="loadVolume" width="70" headerAlign="center" align="right" >配载体积</div>
                    <div field="airlinesId" width="140" headerAlign="center" align="left" data-options='{cacheName:"airlines"}' renderer="commonRender">配载航空公司</div>
                    <div field="flightName" width="70" headerAlign="center" align="center" >配载航班</div>
                    <div field="flightDate" width="70" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">航班日期</div>
                    <div field="shareTransportCostAmount" width="70" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">运费成本</div>
                    <div field="shareGroundAmount" width="70" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">地面成本</div>
                    <div field="shareAirlinesAddCostAmount" width="70" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">附加费成本</div>
                    <div field="shareOtherChargesAmount" width="70" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">其他成本</div>
                    <div field="shareTotalCostAmount" width="70" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">成本合计</div>
                    <div field="shareTotalCostComment" width="140" headerAlign="center" align="center" >成本说明</div>
                </div>
            </div>
        </div>

        <!-- 正单打印 -->
        <div id="printMasterBillPanel" class="mini-window" title="主单打印" style="width:1200px;height:800px;"
             showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
             showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">

            <div property="footer" style="padding:10px;text-align: right">
                选择打印机:
                <select id="printList">
                    <option></option>
                </select>

                <a  class="mini-button" iconCls="icon-ok" onclick="printMasterBill('1')">打印</a>
                <a  class="mini-button" iconCls="icon-ok" onclick="printMasterBill('2')">打印预览</a>
                <a  class="mini-button" iconCls="icon-ok" onclick="printMasterBill('3')">页面设置</a>

                <a  class="mini-button" iconCls="icon-close" onclick="public_onCancel('printMasterBillPanel')">关闭</a>
            </div>


            <!--需要打印的区域-->
            <div id="printArea" style="width: 98%">

            </div>
        </div>


        <script type="text/javascript">
            mini.parse();

            let keyMasterBillCode = mini.get("keyMasterBillCode");
            let keyloadWayId = mini.get("keyloadWayId");
            let keyTransportWayId = mini.get("keyTransportWayId");
            let keyReceiveCustomerName = mini.get("keyReceiveCustomerName");
            let keyOpenMasterBillStartDate = mini.get("keyOpenMasterBillStartDate");
            let keyOpenMasterBillEndDate = mini.get("keyOpenMasterBillEndDate");
            let keyDestCityId = mini.get("keyDestCityId");
            let keyAirportId = mini.get("keyAirportId");
            let keyOutUnitId = mini.get("keyOutUnitId");


            let keyAccountCheckStatusId = mini.get("keyAccountCheckStatusId");

            // 主 grid
            let grid = mini.get("datagrid1");
            // 明细 grid块
            let detailDiv = document.getElementById("detailDiv");

            let detailGrid = mini.get("detailGrid");

            // 已经选择的主单对象
            let selectMasterItem;

            $(function () {

                // 配货方式
                let keyloadWayIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_LOAD_WAY");
                keyloadWayId.load(keyloadWayIdJsonData);

                // 承运方式下拉列表
                let keyTransportWayIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_TRANSPORT_WAY");
                keyTransportWayId.load(keyTransportWayIdJsonData);

                // 对账状态
                let keyAccountCheckStatusIdJsonDate  = commonRenderSysDicDropListByKey("sysDic","XT_DIC_ACCOUNT_CHECK_STATUS");
                keyAccountCheckStatusId.load(keyAccountCheckStatusIdJsonDate);


                // 始发机场下拉列表
                let pullAirportIdJsonData = commonRenderDropList("airport");
                keyAirportId.load(pullAirportIdJsonData);

                // 加载目的城市下拉列表
                let keyDestCityIdJsonData=commonRenderDropList("city");
                keyDestCityId.loadList(keyDestCityIdJsonData,"id","pid");

                // 加载外发单位下拉列表
                let outUnitIdJsonData = commonRenderDropList("outUnit");
                keyOutUnitId.load(outUnitIdJsonData);

                // 加载列表数据
                grid.load();
            });

            function clearSearch(){
                let form = new mini.Form("#queryForm");
                form.clear();
            }

            /**
             * 根据查询条件查询主单
             */
            function searchMasterBill(){
                let form = new mini.Form("#queryForm");
                let data = form.getData(true);
                grid.load(data);
            }

            // 展示主单号时显示其超链接
            function showMasterBillRender(e){
                let masterBillId = e.value;

                let htmlStr = "<a href='javascript:void(0);' onclick='showViewMasterBill(\""+ masterBillId +"\")'>" + masterBillId + "</a>";

                return htmlStr;
            }


            function showViewMasterBill(masterBillId){
                let tabUrl="${base}/pages/master_bill_manage/flight/showUpdateMasterBill?opType=view&id=" + masterBillId;
                parent.window.addTabToMainPage("航空主单查看","航空主单查看",tabUrl);
            }


            /**
             * 加载明细
             */
            function onShowRowDetail(e){
                let grid = e.sender;
                let row = e.record;

                let td = grid.getRowDetailCellEl(row);
                td.appendChild(detailDiv);

                detailDiv.style.display = "block";

                detailGrid.load({masterBillId: row.id});

            }

            function showNativeBillRender(e){
                let nativeBillId = e.value;
                let htmlStr = "<a href='javascript:void(0);' onclick='showViewNativeBill(\""+ nativeBillId +"\")'>" + nativeBillId + "</a>";
                return htmlStr;
            }

            function showViewNativeBill(nativeBillId){
                let tabUrl="${base}/pages/native_bill_manage/showUpdateBill?opType=view&id=" + nativeBillId;
                parent.window.addTabToMainPage("分单查看","分单查看",tabUrl);
            }

            /**
             * 根据选择的主单进行主单编辑
             */
            function editMasterBillShow(){
                let masterBillObjs = grid.getSelecteds();
                if(masterBillObjs.length>0){
                    if(masterBillObjs.length==1){
                        let tabUrl="${base}/pages/master_bill_manage/flight/showUpdateMasterBill?opType=update&id=" + masterBillObjs[0].id;
                        parent.window.addTabToMainPage("航空主单编辑","航空主单编辑",tabUrl);
                    }
                    else{
                        showAlert("编辑时请选择一行！");
                    }
                }
                else{
                    showAlert("请选择需要编辑的对象！");
                }
            }

            /**
             * 根据选择的主单作废主单
             */
            function cancelMasterBill(){
                showAlert(" 作废功能暂未提供！");
            }


            // 结算状态
            let settlementStatus = {uncleared:321, cleared:322};

            // 对账状态
            let accountCheckStatus = {noCheck:431, checked:432};

            /**
             * 无拉货状态检测删除,要求
             * 主单删除时如果主单的对账状态是 已对账或已结算，已拉货是可以进行删除的 则不能删除
             */
            function noPullStatusCheckDeleteMasterBill(){

                // 1.如果分单配载对象调整后的配载件数为0,则表示是全拉货 如果是全拉改配 或 全拉退货,则全需要删除原始的配载信息,同时调整原始分单上的配载状态或退回信息
                // 全拉货还分三种，全拉补发，全拉改配，全拉退客户
                // b_native_bill_pull_cost这张表记录了全拉的成本信息
                //

                // 1.直接删除主单
                // 2.删除单拉货信息
                // 3.恢复分单原始状态

                let masterBillObjs = grid.getSelecteds();
                if(masterBillObjs.length==0){
                    showAlert("请选择需要不检测拉货状态删除的主单!");
                    return;
                }

                // 可以删除的主单号
                let canDeleteMasterBillIds = "";
                // 不可以删除的主单
                let canNotDeleteMasterBillIds = "";

                for(let obj of masterBillObjs){
                    if(obj.settlementStatusId == settlementStatus.uncleared && obj.accountCheckStatusId == accountCheckStatus.noCheck){
                        canDeleteMasterBillIds += obj.id + ",";
                    }
                    else{
                        canNotDeleteMasterBillIds += obj.id + ",";
                    }
                }

                if(canNotDeleteMasterBillIds.length>0){
                    canNotDeleteMasterBillIds = canNotDeleteMasterBillIds.substring(0,canNotDeleteMasterBillIds.length-1);
                    showAlert("主单【" + canNotDeleteMasterBillIds + "】 为【已对账】或【已结算】状态，不能删除!");
                    return;
                }

                if(canDeleteMasterBillIds.length==0){
                    return;
                }

                canDeleteMasterBillIds = canDeleteMasterBillIds.substring(0,canDeleteMasterBillIds.length-1);

                // 弹出删除确认对话框
                mini.confirm("确定无拉货状态检测删除已经选择【" + canDeleteMasterBillIds + "】主单？", " 无拉货状态检测主单删除",
                    function (action) {
                        if (action == "ok") {
                            // String statusFieldName, Long statusId, String billIds,  cacel_status_id
                            let ret = public_getServerData("${base}/pages/master_bill_manage/flight/noPullStatusCheckDeleteMasterBillByMasterBillIds",{masterBillIds:canDeleteMasterBillIds});
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    grid.reload();
                                }
                            });
                        }
                    }
                );

            }

            /**
             * 根据选择的主单作废主单
             */
            function deleteMasterBill(){
                let masterBillObjs = grid.getSelecteds();
                if(masterBillObjs.length==0){
                    showAlert("请选择需要删除的主单!");
                    return;
                }

                // 可以删除的主单
                /**
                 * 主单删除
                 1.主单删除时如果主单的对账状态是 已对账，已拉货 则不能删除
                 2.如果是自发的主单号会被回收，供再次使用
                 3.主单删除时其下的相关配载信息会一并删除
                 5.分单不会删除，但会修改其配载状态为未配载或部分配载，原分单成本及分单利润会调整为0  drop_status_id
                 */
                let canDeleteMasterBillIds = "";
                // 不可以删除的主单
                let canNotDeleteMasterBillIds = "";

                for(let obj of masterBillObjs){
                    if(obj.settlementStatusId == settlementStatus.cleared
                        || obj.accountCheckStatusId == accountCheckStatus.checked
                        || obj.dropStatusId == pullStatus.pull ){
                        canNotDeleteMasterBillIds += obj.id + ",";
                    }
                    else{
                        canDeleteMasterBillIds += obj.id + ",";
                    }
                }

                if(canNotDeleteMasterBillIds.length>0){
                    canNotDeleteMasterBillIds = canNotDeleteMasterBillIds.substring(0,canNotDeleteMasterBillIds.length-1);
                    showAlert("主单【" + canNotDeleteMasterBillIds + "】 为【已拉货、已对账、已结算】，不能删除!");
                    return;
                }

                if(canDeleteMasterBillIds.length==0){
                    return;
                }

                canDeleteMasterBillIds = canDeleteMasterBillIds.substring(0,canDeleteMasterBillIds.length-1);

                // 弹出删除确认对话框
                mini.confirm("确定删除已经选择【" + canDeleteMasterBillIds + "】主单？", "主单删除",
                    function (action) {
                        if (action == "ok") {
                            // String statusFieldName, Long statusId, String billIds,  cacel_status_id
                            let ret = public_getServerData("${base}/pages/master_bill_manage/flight/deleteMasterBillByMasterBillIds",{masterBillIds:canDeleteMasterBillIds});
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    grid.reload();
                                }
                            });
                        }
                    }
                );

            }


            // 拉货状态
            let pullStatus = {notPull:361,pull:362};

            // 主单类型
            let masterBillType = {flight:261,auto:262};

            function dropMasterBillShow() {

                let masterBillObjs = grid.getSelecteds();

                if(masterBillObjs.length == 0){
                    showAlert("请选择需要拉货的主单！");
                    return;
                }

                if(masterBillObjs.length >1 ){
                    showAlert("拉货时请选择单行！");
                    return;
                }

                let masterBillId = masterBillObjs[0].id;

                // 这个地方应该从数据库加载，因为可能做过了现在双重复做,根据 ID 再加载一下对象
                let ret = public_getServerData("${base}/pages/master_bill_manage/flight/queryMasterBillFlightPojoById?masterBillId=" + masterBillId);
                if(!ret.ok){
                    showAlert("主单拉货主单对象加载失败!");
                    return;
                }

                if(ret.data.dropStatusId == pullStatus.pull){
                    showAlert("主单【" + masterBillObjs[0].id + "】已经做过拉货，不能重复拉货!");
                    return;
                }

                let tabUrl="${base}/pages/master_bill_manage/pull/showPullAdd?masterBillId=" + masterBillId + "&masterBillTypeId=" + masterBillType.flight;
                parent.window.addTabToMainPage("主单拉货","主单拉货",tabUrl);

            }

            /**
             * 设置底部统计样式
             * @param e
             */
            function summaryRight(e){
                e.cellStyle="text-align:right;color:red;font-size:18px;font-weight:bold";
            }

            /**
             * 正单打印
             */

            let displayHtml;

            // 发货人付款方式类型
            let deliveryCustomerPaymentMethodType = {cash:151,alipay:152,weChat:153,unionpay:154,arrears:156,noMoneyReceive:157,toPay:158};

            function showPrintMasterBill(){
                let masterBillObjs = grid.getSelecteds();
                if(masterBillObjs.length>0){
                    if(masterBillObjs.length==1){
                        // 显示拉货的列表信息  airPullGoodsPanel

                        selectMasterItem = masterBillObjs[0];

                        // 根据主单ID 获取主单配载的分单对象
                        let ret = public_getServerData("${base}/pages/master_bill_manage/flight/queryBNativeBillPojoListByMasterBillId?masterBillId=" + selectMasterItem.id);
                        if(!ret.ok){
                            showAlert("主单下不包含配载分单，可能是由于拉货导致的!");
                            return;
                        }

                        let billArray = ret.data;
                        if(billArray.length == 0){
                            showAlert("根据主单号获取配载分单信息失败，请查看主单下是否包含配载分单信息!");
                            return;
                        }

                        public_showModelAtPos("printMasterBillPanel", "center", "middle");


                        let row1Html = "<div style='font-weight:bold;font-size: 20px'>To:" + selectMasterItem.receiveCustomerName + "</div>"

                        // 第二行直接输出
                        let agentCompanyId = selectMasterItem.agentCompanyId;
                        let agentCompanyObj = commonRendderObjByKeyAndId("sysCompany",agentCompanyId);
                        let masterBillForeignCompanyObj = commonRendderObjByKeyAndId("sysCompany",agentCompanyObj.masterBillForeignCompanyId);
                        let masterBillForeignCompanyName = masterBillForeignCompanyObj.name;
                        let row2Html = "<div style='width: 100%;text-align: center;font-weight: bold;font-size: 20px'>" + masterBillForeignCompanyName + "出港货物清单</div>";

                        // 第三行
                        let row3Html = "<div style='width: 100%;font-size: 15px;margin-top: 10px'>"
                        row3Html += "<span style='width: 25%;display:inline-block;'>提货单号:" + selectMasterItem.id + "</span>";
                        row3Html += "<span style='width: 25%;display:inline-block;'>班次日期:" + public_cstDataConvert(selectMasterItem.flightDate) + "</span>";
                        row3Html += "<span style='width: 25%;display:inline-block;'>班次号:" + selectMasterItem.flightName + "</span>";
                        row3Html += "<span style='width: 20%;display:inline-block;'>起飞时间:" + selectMasterItem.planTakeOffTime + "</span>";
                        row3Html += "</div>";

                        // 第四行，分单显示区域

                        let totalAgentDeliveryCharge = 0;
                        let totalDeliveryToPayAmount = 0;
                        let totalCollectionMoney = 0;

                        let tableHtml = "<table width='100%' border='1' cellspacing='0' cellpadding='0'>";
                        tableHtml += "<tr>";
                        tableHtml += "<th style='text-align: center'>分单号</th>"
                        tableHtml += "<th style='text-align: center'>件数</th>"
                        tableHtml += "<th style='text-align: center'>实重</th>"
                        // tableHtml += "<th style='text-align: center'>计重</th>"
                        tableHtml += "<th style='text-align: center'>目的站</th>"
                        tableHtml += "<th style='text-align: center'>品名/包装</th>"
                        tableHtml += "<th style='text-align: center'>收货人</th>"
                        tableHtml += "<th style='text-align: center'>提货方式</th>"
                        tableHtml += "<th style='text-align: center'>签收方式</th>"
                        tableHtml += "<th style='text-align: center'>派送费</th>"
                        tableHtml += "<th style='text-align: center'>收货人付款方式</th>"
                        tableHtml += "<th style='text-align: center'>收货人付款金额</th>"
                        tableHtml += "<th style='text-align: center'>代收货款</th>"
                        tableHtml += "<th style='text-align: center'>备注</th>"
                        tableHtml += "</tr>";

                        // 通过循环输出分单位对象并累计相应数据
                        // let deliveryCustomerPaymentMethodType = {cash:151,alipay:152,weChat:153,unionpay:154,arrears:156,noMoneyReceive:157,toPay:158};
                        for(let billObj of billArray){
                            totalAgentDeliveryCharge += public_toNumber(billObj.agentDeliveryCharge,0);
                            if(billObj.deliveryCustomerPaymentMethodId == deliveryCustomerPaymentMethodType.toPay){
                                totalDeliveryToPayAmount += public_toNumber(billObj.deliveryCustomerPaymentAmount,0);
                            }
                            totalCollectionMoney += public_toNumber(billObj.collectionMoney,0);

                            let destCityName = commonRendderNameByKeyAndId("city",billObj.destCityId); // 目的站
                            let packingWayName = commonRendderNameByKeyAndId("sysDic",billObj.packingWayId); // 包装
                            let pickUpGoodsWayName = commonRendderNameByKeyAndId("sysDic",billObj.pickUpGoodsWayId); // 提货方式
                            let receiveCustomerPaymentMethodName = "";
                            let receiveCustomerPaymentAmount = "";
                            if(!public_isEmpty(billObj.receiveCustomerPaymentMethodId) && billObj.receiveCustomerPaymentMethodId == 165){
                                // 注意165代表收货人付款方式
                                receiveCustomerPaymentMethodName = commonRendderNameByKeyAndId("sysDic",billObj.receiveCustomerPaymentMethodId);  // 收货人付款方式
                                if(billObj.receiveCustomerPaymentAmount>0){
                                    receiveCustomerPaymentAmount = billObj.receiveCustomerPaymentAmount;
                                }
                            }
                            let signChooseName = "";
                            if(!public_isEmpty(billObj.signChooseId)){
                                signChooseName = commonRendderNameByKeyAndId("sysDic",billObj.signChooseId); // 签收方式
                            }
                            tableHtml += "<tr>";

                            tableHtml += "<td style='text-align: center'>" + billObj.id + "</td>"; // 分单号
                            tableHtml += "<td style='text-align: center'>" + billObj.totalNumber + "</td>";  // 件数
                            tableHtml += "<td style='text-align: center'>" + billObj.actualWeight + "</td>"; // 实重
                            // tableHtml += "<td style='text-align: center'>" + billObj.chargeableWeight + "</td>";  // 计重
                            tableHtml += "<td style='text-align: center'>" + destCityName + "</td>"; //  目的站
                            tableHtml += "<td style='text-align: center'>" + billObj.goodsName + "/" + packingWayName + "</td>";  // 品名/包装
                            tableHtml += "<td style='padding-left: 5px'>" + billObj.receiveCustomerName + "<br/>" + billObj.receiveCustomerPhone + "<br/>" + billObj.receiveCustomerAddress + "</td>"; // 收货人
                            tableHtml += "<td style='text-align: center'>" + pickUpGoodsWayName + "</td>"; // 提货方式
                            tableHtml += "<td style='text-align: center'>" + signChooseName + "</td>"; // 签收方式
                            tableHtml += "<td style='text-align: center'>" + billObj.agentDeliveryCharge + "</td>"; // 代理派送费
                            // tableHtml += "<td style='text-align: center'>" + deliveryCustomerPaymentMethodName + " / " + billObj.deliveryCustomerPaymentAmount + "</td>"; // 发货人付款方式
                            tableHtml += "<td style='text-align: center'>" + receiveCustomerPaymentMethodName + "</td>"; // 收货人付款方式
                            tableHtml += "<td style='text-align: center'>" + receiveCustomerPaymentAmount + "</td>"; // 收货人付款金额
                            tableHtml += "<td style='text-align: center'>" + billObj.collectionMoney + "</td>"; //  代收货款
                            tableHtml += "<td style='padding-left: 5px'>" + billObj.comment + "</td>"; //  备注

                            tableHtml += "</tr>";

                        }

                        tableHtml += "</table>"

                        let row4Html = "<div style='width: 100%;font-size: 15px'>" + tableHtml + "</div>";

                        // 第五行
                        let row5Html = "<div  style='width: 100%;font-size: 15px'>";
                        row5Html += "<span style='width:15%; display:inline-block;'>主单总件数:" + selectMasterItem.totalNumber + "</span>";
                        row5Html += "<span style='width:15%; display:inline-block;'>主单计重:" + selectMasterItem.chargeableWeight + "</span>";
                        row5Html += "<span style='width:15%; display:inline-block;'>派送费合计:" + public_round2(totalAgentDeliveryCharge) + "</span>";
                        row5Html += "<span style='width:15%; display:inline-block;'>发货人到付合计:" + public_round2(totalDeliveryToPayAmount) + "</span>";
                        //row5Html += "<span style='width:15%; display:inline-block;'>收货人付款合计:" + public_round2(totalReceiveCustomerPaymentAmount) + "</span>";
                        row5Html += "<span style='width:15%; display:inline-block;'>代收款合计:" + public_round2(totalCollectionMoney) + "</span>";
                        row5Html += "</div>";



                        // 第六行
                        let masterBillComment = selectMasterItem.comment;
                        if(public_isEmpty(masterBillComment) || masterBillComment=="null"){
                            masterBillComment = "";
                        }
                        let row6Html = "<div style='width: 100%;font-size: 15px'>主单备注:" + masterBillComment + "</div>";
                        // 等待打印与显示的HTML
                        displayHtml = row1Html + row2Html + row3Html + row4Html + row5Html + row6Html;

                        $("#printArea").empty();
                        $("#printArea").append(displayHtml);

                        getPrinterlist("printList");

                    }
                    else{
                        showAlert("打印请选择单行！");
                    }
                }
                else{
                    showAlert("请选择需要打印的主单！");
                }
            }

            /**
             * 根据ID加载打印机列表
             */
            function getPrinterlist(printerId) {
                let printList = $("#"+printerId); //打印机下拉列表
                // 清空下拉列表
                printList.empty();
                printList.prepend("<option value='-1'>请选择</option>");

                let lodop = getLodop($("#LODOP_OB"),$("#LODOP_EM"));

                let printerAccount = lodop.GET_PRINTER_COUNT();

                for (let i = 0; i < printerAccount; i++) {
                    let printerIndex = i.toString();
                    let printerName = lodop.GET_PRINTER_NAME(i);
                    printList.append("<option value='" + printerIndex + "'>" + printerName + "</option>");
                }
            }



            function printMasterBill(opType){

                let selectedPrinterName = $("#printList").find("option:selected").text();;
                if(public_isEmpty(selectedPrinterName) || selectedPrinterName=="请选择"){
                    showAlert("请选择指定打印机!");
                    return;
                }

                let LODOP = getLodop($("#LODOP"), $("#LODOP_EM"));
                //lodop.PRINT_INIT("打印详细信息");
                //lodop.PRINT_INITA(-107, -90, 800, 600, "套打EMS的模板");
                //lodop.SET_PRINT_PAGESIZE(1, "90mm", "55mm", ""); //设置纸张高度

                LODOP.PRINT_INIT("正单位打印");
                LODOP.SET_PRINT_PAGESIZE(2, 0, 0,"A4"); // A4 横向

                // ADD_PRINT_HTM(Top,Left,Width,Height,strHtmlContent)
                LODOP.ADD_PRINT_HTM("10mm","5mm", "98%","80%",displayHtml);

                if (opType == "1") {
                    LODOP.SET_PRINTER_INDEXA(selectedPrinterName)
                    LODOP.PRINT(); //直接打印

                }else if (opType == "2") {
                    LODOP.SET_PRINTER_INDEXA(selectedPrinterName)
                    LODOP.PREVIEW(); //打印预览
                } else {
                    LODOP.PRINT_SETUP(); //打印维护
                }
            }


        </script>
    </body>
</html>